<template>
  <div>
    <!-- 不知道什么时候能拿到max，因为是异步获取的：使用watch监听 -->
    <h5 class="mui-content-padded">限定最小值和最大值(1~9)</h5>
    <div class="mui-numbox" data-numbox-min="1" :data-numbox-max="max">
      <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
      <input
        id="test"
        class="mui-input-numbox"
        type="number"
        value="1"
        @change="countChanged"
        ref="numbox"
      />
      <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
  </div>
</template>

<script>
import mui from "../../mui/dist/js/mui.js";
export default {
  data() {
    return {};
  },
  mounted() {
    //初始化数字选择框组件
    mui(".mui-numbox").numbox();
  },
  methods: {
    countChanged() {
      // console.log(this.$refs.numbox.value);
      this.$emit('getcount', parseInt(this.$refs.numbox.value))
    }
  },
  props: ["max"],
  watch: {
    'max': function(newVal, oldVal){
      //使用jsAPI设置numbox的最大值
      mui(".mui-numbox").numbox().setOption('max',newVal)
    }
  },
};
</script>

<style lang="scss" scoped>
</style>